const path=require('path');
const webpack = require('webpack');
module.exports = {
    mode: "development", //webpack要指定编译类型，可在此处写，也可用命令写
    entry: [
        "./src/index.js"//入口文件
    ],
    output: {
        path: path.resolve(__dirname, './build'),//输出目录及文件
        filename: 'main.js'
    },
    devServer: {
        proxy:{
            '/api':{
                target: 'http://localhost:3010/',
                changeOrigin: true,
                pathRewrite: {
                '^/api': '/api'
                }
            }
        },
        inline: true,
        port: 8090,
        
    },
    module: {
        rules: [//此处不能在用loders,需用rules
            {
                test: /\.js|jsx$/,
                loader: 'babel-loader',//转化成浏览器能解析的js
                exclude: path.resolve(__dirname, 'node_modules'),
                query:{
                    presets:['es2015','react','stage-0'] //必须先安装babel-preset-es2015和babel-preset-react
                }
            },
            { test: /\.css$/,  use: [
                {
                  loader: "style-loader",
                  options: {
                    singleton: true // 处理为单个style标签
                  }
                },
                {
                  loader: "css-loader",
                  options: {
                    minimize: true // css代码压缩
                  }
                }
              ] }//css样式处理
        ]
    },
    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),//错误处理
        new webpack.HotModuleReplacementPlugin()//热更新插件和react-hot-loader配合使用
    ],


}
